package com.todo.content.application.backend.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.todo.common.common.entity.response.BizPageResponse;
import com.todo.common.common.entity.response.BizResponse;
import com.todo.common.common.entity.response.page.PageResult;
import com.todo.common.common.enums.BizErrorCodeEnum;
import com.todo.common.common.enums.EnableTypeEnum;
import com.todo.common.common.exception.BizException;
import com.todo.content.application.backend.service.ContentClassifyBackendService;
import com.todo.content.application.convert.ContentConvert;
import com.todo.content.application.entity.bo.ContentClassifyBO;
import com.todo.content.application.entity.condition.ContentClassifyConditionBO;
import com.todo.content.application.service.ContentClassifyService;
import com.todo.content.iface.backend.request.*;
import com.todo.content.iface.backend.response.ContentClassifyDetailByIdResp;
import com.todo.content.iface.backend.response.QueryContentClassifyByConditionResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (ContentClassify)表服务实现类
 *
 * @author zhangwenxiang
 * @since 2024-03-04 00:19:45
 */
@Slf4j
@Service("contentClassifyBackendService")
public class ContentClassifyBackendServiceImpl implements ContentClassifyBackendService {

    @Resource
    private ContentClassifyService contentClassifyService;

    @Override
    public BizResponse<Boolean> insertContentClassify(InsertContentClassifyReq req) {
        if (req == null || !req.baseCheck()) {
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR);
        }
        ContentClassifyBO contentClassifyBO = ContentConvert.convertToContentClassifyBO(req);
        Boolean insertResult = contentClassifyService.insertContentClassify(contentClassifyBO);
        log.info("ContentClassifyBackendService#insertContentClassify 新增内容分类信息完成 入参：【{}】出参：【{}】", JSONObject.toJSONString(req), insertResult);
        return BizResponse.success(insertResult);
    }

    @Override
    public BizResponse<Boolean> updateContentClassifyById(UpdateContentClassifyByIdReq req) {
        if (req == null || !req.baseCheck()) {
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR);
        }
        ContentClassifyBO contentClassifyBO = ContentConvert.convertToContentClassifyBO(req);
        Boolean updateResult = contentClassifyService.updateContentClassifyById(contentClassifyBO);
        log.info("ContentClassifyBackendService#updateContentClassifyById 更新内容分类信息完成 入参：【{}】出参：【{}】", JSONObject.toJSONString(req), updateResult);
        return BizResponse.success(updateResult);
    }

    @Override
    public BizResponse<Boolean> removeContentClassifyById(RemoveContentClassifyByIdReq req) {
        if (req == null || !req.baseCheck()) {
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR);
        }
        Boolean removeResult = contentClassifyService.removeContentClassifyById(req.getClassifyId());
        log.info("ContentClassifyBackendService#removeContentClassifyById 删除内容分类信息完成 入参：【{}】出参：【{}】", JSONObject.toJSONString(req), removeResult);
        return BizResponse.success(removeResult);
    }

    @Override
    public BizResponse<Boolean> enableContentClassifyById(EnableContentClassifyByIdReq req) {
        if (req == null || !req.baseCheck()) {
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR);
        }
        Boolean enableResult = contentClassifyService.enableContentClassifyById(req.getClassifyId(), EnableTypeEnum.getByType(req.getEnable()));
        log.info("ContentClassifyBackendService#enableContentClassifyById 启用禁用内容分类信息完成 入参：【{}】出参：【{}】", JSONObject.toJSONString(req), enableResult);
        return BizResponse.success(enableResult);
    }

    @Override
    public BizResponse<ContentClassifyDetailByIdResp> queryContentClassifyById(QueryContentClassifyByIdReq req) {
        if (req == null || !req.baseCheck()) {
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR);
        }
        ContentClassifyBO contentClassifyBO = contentClassifyService.queryContentClassifyById(req.getClassifyId());
        log.info("ContentClassifyBackendService#queryContentClassifyById 查询内容分类信息完成 入参：【{}】出参：【{}】", JSONObject.toJSONString(req), JSONObject.toJSONString(contentClassifyBO));
        return BizResponse.success(ContentConvert.convertToContentClassifyDetailByIdResp(contentClassifyBO));
    }

    @Override
    public BizPageResponse<QueryContentClassifyByConditionResp> queryContentClassifyByCondition(QueryContentClassifyByConditionReq req) {
        if (req == null || !req.baseCheck()) {
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR);
        }
        ContentClassifyConditionBO conditionBO = ContentConvert.convertToContentClassifyConditionBO(req);
        PageResult<ContentClassifyBO> pageResult = contentClassifyService.queryContentClassifyByPage(conditionBO);
        return BizPageResponse.success(ContentConvert.convertToQueryContentClassifyByConditionRespPage(pageResult));
    }
}
